package com.oa.pm.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.joneying.common.web.response.Resp;
import com.oa.core.BaseController;
import com.oa.pm.entity.CheckIn;
import com.oa.pm.service.ICheckInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(description = "签到接口")
@RequestMapping("/checkIn")
@RestController
public class CheckInController extends BaseController {


    @Autowired
    private ICheckInService checkInService;

    @Description("签到")
    @ApiOperation(value = "签到")
    @GetMapping("/list")
    public Resp list(
            @RequestParam(required = false) String name,
            @RequestParam(required = false)  Date beginTime,
            @RequestParam(required = false)  Date endTime,
            @RequestParam(required = false)  Integer pageNum,
            @RequestParam(required = false)  Integer pageSize){
        return new Resp().success(checkInService.findCheckInList(name, beginTime, endTime, pageNum, pageSize));
    }


    @Description("签到")
    @ApiOperation(value = "签到")
    @PostMapping("")
    public Resp add(@RequestBody CheckIn checkIn){
        checkIn.setUserId(getLoginUserId());
        checkIn.setCheckInTime(new Date());
        if(checkInService.insert(checkIn)){
            return new Resp().success();
        }
        return new Resp().failure();
    }
}
